<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts 可视化分析淘宝双11</title>
    <!-- 引入 echarts.js -->
    <script type="text/javascript" src="js/echarts.min.js"></script>
    <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
    <link type='text/css' href="css/style.css" rel="stylesheet"/>
    <!--    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>-->
    <!--    <script src="https://cdn.bootcss.com/echarts/4.6.0/echarts.min.js"></script>-->
</head>
<body>
<div class='header'>
    <p>ECharts 可视化分析淘宝双11</p>
</div>
<div class="content">
    <div class="nav">
        <ul>
            <li><a href="index">所有买家各消费行为对比</a></li>
            <li><a href="index1">男女买家交易对比</a></li>
            <li><a href="index2">男女买家各个年龄段交易对比</a></li>
            <li class="current"><a href="#">商品类别交易额对比</a></li>
            <li><a href="index4">各省份的总成交量对比</a></li>
        </ul>
    </div>
    <div class="container" style="width: 700px;height: 700px">
        <div class="title">商品类别交易额对比</div>
        <div class="show">
            <div class='chart-type'>柱状图</div>
            <div id="main"></div>
        </div>
    </div>
</div>
<script>
    //基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    // //数据库双11 所有买家消费行为比例
    var x = []
    var y = []
    //AJAX接收数据主体
    $.ajax({
        type: "GET",
        url: "/catalogTop5",
        dataType: "json",
        async: false,
        success: function (result) {
            for (var i = 0; i < result.length; i++) {
                x.push(result[i].cat_id);
                y.push(result[i].num);
            }
        },
        error: function (errorMsg) {
            alert("获取后台数据失败！");
        }
    });


    var option = {
        color: ['#3398DB'],

        title: {
            text: '商品类别交易额对比'
        },

        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        legend: {
            data: ['交易额']
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [
            {
                type: 'category',
                data: x,
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '交易额',
                type: 'bar',
                barWidth: '60%',
                data: y
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
</script>
</body>
</html>
